<template>
    <div class="em-popover">
        <div class="em-popover-cont">
            <div class="em-popover-title">
                <p>新增/修改</p>
                <span @click="cancel"></span>
            </div>
            <div class="em-popover-cont-from">
                <el-form :model="formQuery" size="mini">
                    <el-form-item label="专家姓名：" label-width="120px">
                        <el-input :disabled="inputDisabled" size="mini" v-model="formQuery.name"></el-input>
                    </el-form-item>
                    <el-form-item label="账号：" label-width="120px">
                        <el-input :disabled="inputDisabled"  size="mini" v-model="formQuery.mobile"></el-input>
                    </el-form-item>
                    <el-form-item label="单位：" label-width="120px">
                        <el-input size="mini" v-model="formQuery.department"></el-input>
                    </el-form-item>
                </el-form>
                <div class="form-btn">
                    <el-button size="small" @click.stop="cancel" round>取消</el-button>
                    <el-button type="primary" size="small" @click.stop="commit" round>确定</el-button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import Qs from 'qs'
    import { updateExpert,register3 } from '@/service/api'
    export default {
        name: "emPopover",
        data() {
            return {
                formQuery:{
                    name:'',
                    mobile:'',
                    department:''
                },
                inputDisabled:false
            }
        },
        props:{
            manageInfo:Object
        },
        created() {
            if(this.manageInfo.id !== undefined){
                this.inputDisabled = true;
                this.formQuery = Object.assign({},this.manageInfo);
            }
        },
        methods:{
            cancel(){
                this.$emit('update:showPopover',false)
            },
            commit(){
                if(this.manageInfo.id == undefined){
                    this.handleRegister3()
                }else {
                    this.handleUpdateExpert()
                }
            },
            handleRegister3() { //新增
                let params = this.formQuery;
                register3(Qs.stringify(params)).then(res => {  //
                    if (res.code == 200) {
                        console.log(res)
                        this.setSuccess(res.message)
                    } else {
                        console.log(res)
                    }
                });
            },
            handleUpdateExpert() { //修改
                let params = this.formQuery;
                updateExpert(Qs.stringify(params)).then(res => {  //
                    if (res.code == 200) {
                        console.log(res)
                        this.setSuccess(res.message)
                    } else {
                        console.log(res)
                    }
                });
            },
            setSuccess(message) {
                this.$message({
                    message: message,
                    type: 'success'
                });
                this.cancel();
                this.$emit('commitPopover')
            }
        }
    }
</script>

<style scoped>
    .em-popover {
        position: fixed;
        top: 0px;
        left: 0px;
        z-index: 2;
        height: 100%;
        width: 100%;
        background: rgba(0, 0, 0, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .em-popover-cont{
        background: white;
        width: 28%;
        min-width: 480px;
        min-height: 400px;
        font-size: 14px;
        box-shadow: 3px 1px 12px 1px #00000069;
        border-radius: 10px;
        padding-bottom: 56px;
        overflow-y: auto;
        position: relative;
    }
    .em-popover-title {
        width: 100%;
        min-width: 480px;
        text-align: center;
        font-size: 22px;
        font-weight: bold;
        color: white;
        padding: 8px 0px;
        background: url('../../assets/reviews/icon_tu@2x.png') no-repeat;
        background-size: 100% 100%; /* 背景图完整覆盖容器，但宽高比例变了，图片变形。*/
    }
    .em-popover-title > span{
        display: block;
        width: 20px;
        height: 20px;
        background: url("../../assets/reviews/icon_shanchu@2x.png") no-repeat;
        background-size: 100% 100%;
        position: absolute;
        right: 30px;
        top: 14px;
        cursor: pointer;
    }
    .em-popover-cont-from{
        width: 80%;
        margin: 60px auto 0;
    }
    .em-popover-cont-from >>> .el-form-item--mini.el-form-item{
        margin-bottom: 28px;
    }
    .form-btn{
        width: 80%;
        margin: 60px auto 0;
        text-align: center;
    }
    .form-btn >>> .el-button{
        width: 90px;
        margin: 0 20px;
    }
</style>
